package com.xinqi.modules.course.image.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.image.client.CourseImageClient;
import com.xinqi.modules.course.image.dto.req.CourseImageCreateDTO;
import com.xinqi.modules.course.image.dto.req.CourseImageQueryDTO;
import com.xinqi.modules.course.image.dto.req.CourseImageUpdateDTO;
import com.xinqi.modules.course.image.dto.rsp.CourseImageResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 课程背景封面图表降级处理
 *
 * @author: system
 * @date: 2023/03/22
 */
@Slf4j
@Component
public class CourseImageFallbackFactory implements FallbackFactory<CourseImageClient> {

    @Override
    public CourseImageClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new CourseImageClient() {
            @Override
            public R<PageInfo<CourseImageResultDTO>> page(CourseImageQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<CourseImageResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(CourseImageCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, CourseImageUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
